/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package icexam.dao;

import icexam.util.PropertyUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Ethan
 */
public class DBConnect {

    static final String Ip = PropertyUtil.getIP();


    static final String URL = "jdbc:postgresql://"
            + Ip+ ":5432/icex";
   static final String USER = "postgres";
   static final String PASSWORD = "1234";
   static final String DRIVER = "org.postgresql.Driver";
   private static Connection con = null;
    public static Connection getConnection(){
      
      try {
         Class.forName(DRIVER);
         con = DriverManager.getConnection(URL, USER, PASSWORD);
      }
        catch (SQLException ex) {
            Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "数据库连接失败，请确认数据库IP是否正常。");
        }      catch(ClassNotFoundException e) {

         System.out.println(e.getMessage());
         System.exit(-1);
      }
      return con;
   }
}
